package com.asiainfo.ssm.execute.dao.impl;

import java.rmi.RemoteException;
import java.util.HashMap;

import com.asiainfo.ssm.execute.bo.BOExecOrderRespEngine;
import com.asiainfo.ssm.execute.dao.interfaces.IExecOrderRespDAO;
import com.asiainfo.ssm.execute.ivalues.IBOExecOrderRespValue;

public class ExecOrderRespDAOImpl implements IExecOrderRespDAO {

	@Override
	public void saveOrderResps(IBOExecOrderRespValue[] execOrderRespValues) throws Exception, RemoteException {
		for (IBOExecOrderRespValue iboExecOrderRespValue : execOrderRespValues) {
			if(iboExecOrderRespValue.isNew() || iboExecOrderRespValue.getRespId() ==0){
				iboExecOrderRespValue.setRespId(BOExecOrderRespEngine.getNewId().longValue());
			}
		}
		BOExecOrderRespEngine.save(execOrderRespValues);
	}

	@Override
	public void saveOrderResp(IBOExecOrderRespValue execOrderRespValue) throws Exception, RemoteException {
		BOExecOrderRespEngine.save(execOrderRespValue);
	}

	@Override
	public IBOExecOrderRespValue[] getOrderRespList(int mod, int modValue,int rowNum) throws Exception, RemoteException {
		String sql = "where mod(RESP_ID,:mod) = :modValue and rownum = :rowNum order by resp_id";
		HashMap parameters =  new HashMap<>();
		parameters.put("rowNum", rowNum);
		parameters.put("modValue", modValue);
		parameters.put("mod", mod);

		IBOExecOrderRespValue[] respList = BOExecOrderRespEngine.getBeans(sql,parameters);
		return respList;
	}

	@Override
	public void deleteOrderResps(IBOExecOrderRespValue[] execOrderRespValues) throws Exception, RemoteException {
		for (IBOExecOrderRespValue iboExecOrderRespValue : execOrderRespValues) {
			iboExecOrderRespValue.delete();
		}
		BOExecOrderRespEngine.save(execOrderRespValues);
	}

}
